Pass the `arg_opts` from the command line further on to the CompileOptions.
authorSondre Lefsaker <sondrele@stud.ntnu.no>
Fri, 1 May 2015 23:01:30 +0000 (01:01 +0200)
committerSondre Lefsaker <sondrele@stud.ntnu.no>
Fri, 1 May 2015 23:21:10 +0000 (01:21 +0200)
- The new tests verifies that the extra arguments gets appended to the command. One is for lib and one is for main
- Currently the arguments gets passed on to *every* target that gets built, so the tests only contain one file each

src/bin/rustc.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_rustc.rs

index f3d6fdf9defecf8ab65809fa7aee90cb65d2ca1e..72c8ad98da5fd6f324728ff25edc462bb6acdb12 100644 (file)
@@ -85,7 +85,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
                                         &options.flag_test,
                                         &options.flag_example,
                                         &options.flag_bench),
-        target_rustc_args: None,
+        target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]),
     };
 
     ops::compile(&root, &opts).map(|_| None).map_err(|err| {
index 4cb5f5b9b18c5fb840c0603b3e4f490efcb574b7..d80b750a15085f78e1a394bc3c91efe45f89666e 100644 (file)
@@ -665,6 +665,10 @@ fn build_base_args(cx: &Context,
         cmd.arg("-g");
     }
 
+    if let Some(ref args) = cx.build_config.target_rustc_args {
+        cmd.args(args);
+    }
+
     if debug_assertions && opt_level > 0 {
         cmd.args(&["-C", "debug-assertions=on"]);
     } else if !debug_assertions && opt_level == 0 {
index d119945a0c0495676ae553b5e07bb5d63487b7a0..ccc90e18bd0f11fe74c4951f7a6fca099abfe294 100644 (file)
@@ -6,10 +6,14 @@ use hamcrest::{assert_that};
 fn setup() {
 }
 
-fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
+fn verbose_output_for_target(lib: bool, p: &ProjectBuilder) -> String {
+    let (target, kind) = match lib {
+        true => ("lib", "lib"),
+        false => ("main", "bin"),
+    };
     format!("\
 {compiling} {name} v{version} ({url})
-{running} `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
+{running} `rustc src{sep}{target}.rs --crate-name {name} --crate-type {kind} -g \
         --out-dir {dir}{sep}target{sep}debug \
         --emit=dep-info,link \
         -L dependency={dir}{sep}target{sep}debug \
@@ -17,9 +21,14 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
 ",
             running = RUNNING, compiling = COMPILING, sep = SEP,
             dir = p.root().display(), url = p.url(),
+            target = target, kind = kind,
             name = "foo", version = "0.0.1")
 }
 
+fn verbose_output_for_target_with_args(lib: bool, p: &ProjectBuilder, args: &str) -> String {
+    verbose_output_for_target(lib, p).replace(" -g ", &format!(" -g {} ", args))
+}
+
 test!(build_lib_for_foo {
     let p = project("foo")
         .file("Cargo.toml", r#"
@@ -37,5 +46,48 @@ test!(build_lib_for_foo {
     assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo"),
                 execs()
                 .with_status(0)
-                .with_stdout(verbose_output_for_lib(&p)));
+                .with_stdout(verbose_output_for_target(true, &p)));
+});
+
+test!(build_lib_and_allow_unstable_options {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "foo"
+            version = "0.0.1"
+            authors = ["wycats@example.com"]
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/lib.rs", r#" "#);
+
+    assert_that(p.cargo_process("rustc").arg("--lib").arg("-v").arg("foo")
+                .arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(0)
+                .with_stdout(verbose_output_for_target_with_args(true, &p,
+                                                                 "-Z unstable-options")));
+});
+
+test!(build_main_and_allow_unstable_options {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "foo"
+            version = "0.0.1"
+            authors = ["wycats@example.com"]
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {}
+        "#);
+
+    assert_that(p.cargo_process("rustc").arg("-v").arg("foo")
+                .arg("--").arg("-Z").arg("unstable-options"),
+                execs()
+                .with_status(0)
+                .with_stdout(verbose_output_for_target_with_args(false, &p,
+                                                                 "-Z unstable-options")));
 });